package cn.com.lushunming.rdbmserver.service;

import cn.com.lushunming.rdbmserver.entity.User;
import cn.com.lushunming.rdbmserver.persient.UserMapper;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * userdetail service
 * 的实现
 */
@Transactional
@Service("userDetailServiceImpl")
public class UserDetailServiceImpl implements UserDetailsService {
    @Resource
    private UserMapper userMapper;

    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        User user = userMapper.loadUserByUsername(s);
        org.springframework.security.core.userdetails.User userDetails = new org.springframework.security.core.userdetails.User(user.getUserName(), user.getPassword(), new ArrayList<GrantedAuthority>());
        return userDetails;
    }
}
